package com.spark.market.service.impl;

import com.spark.market.api.dto.SequenceInfo;
import com.spark.market.common.utils.AssertUtils;
import com.spark.market.dal.model.SequenceModel;
import com.spark.market.service.SequenceQueryCoreService;
import com.spark.market.service.manager.SequenceManager;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class SequenceQueryCoreServiceImpl implements SequenceQueryCoreService {
    @Resource
    SequenceManager sequenceManager;

    @Override
    public SequenceInfo querySequenceId(String name) {
        AssertUtils.isNotNull(name, "name is null");
        SequenceModel sequenceModel = sequenceManager.querySequenceInfo(name);
        return convertFromSequenceModel(sequenceModel);
    }

    public SequenceInfo convertFromSequenceModel(SequenceModel sequenceModel){
        if (sequenceModel == null){
            return null;
        }
        SequenceInfo sequenceInfo = new SequenceInfo();
        BeanUtils.copyProperties(sequenceModel, sequenceInfo);
        return sequenceInfo;
    }
}
